import Rules from '@/utils/rules'
import { TableColumnsType} from "antd"

export type shippingAddressSaveType = {
  address_name: string,
  provinceId: number,
  cityId: number,
  districtId: number,
  mobile: string,
  remark: string,
  tag: '家'| '公司'| '学校'| '父母'| '朋友'
  isDefault: "0" | "1"
}

export type shippingAddressList = {
  address: string
  tag: string
  isDefault: number
  address_name: string
  mobile: string
  id: number
}
export const shippingAddressRules = {
  address_name: [
    {required: true, message: '请输入收货人名称'}
  ],
  provinceId: [
    {required: true, message: '请选择省'}
  ],
  cityId: [
    {required: true, message: '请选择市'}
  ],
  districtId: [
    {required: true, message: '请选择区'}
  ],
  mobile: [
    {required: true, message: '请输入联系电话'},
    {
      pattern: Rules.subscriber("phone"),
      message: "请输入正确的联系电话"
    }
  ],
  remark: [
    {required: true, message: '请输入详细地址'}
  ],
  tag: [
    {required: true, message: '请选择地址标签'}
  ]
}


export const shippingAddressColumns = (jsx): TableColumnsType<shippingAddressList> => {
  return [
    {
      title: "收件人姓名",
      width: 200,
      align: "center",
      dataIndex: "address_name"
    },
    {
      title: "联系电话",
      width: 200,
      align: "center",
      dataIndex: "mobile"
    },
    {
      title: "收件地址",
      align: "center",
      dataIndex: "address"
    },
    {
      title: "标签",
      align: "center",
      width: 100,
      dataIndex: "tag"
    },
    {
      align: "center",
      dataIndex: "isDefault",
      title: "默认",
      width: 80,
      render: (text) => {
        if (text === 0) {
          return "否"
        }
        return '是'
      }
    },
    {
      title: "操作",
      width: 200,
      align: "center",
      dataIndex: "isDefault",
      render: jsx
    },
  ]
}
